package logic

import (
	"context"
	"errors"
	"tiktok_src/cache"

	"tiktok_src/internal/svc"
	"tiktok_src/tiktook"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartListLogic {
	return &CartListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartListLogic) CartList(in *tiktook.CartListRequest) (*tiktook.CartListResponse, error) {
	// todo: add your logic here and delete this line
	list, err := cache.CartList(int(in.UserId))
	if err != nil {
		logx.Info("购物车列表信息错误", err)
		return nil, errors.New("购物车列表信息错误")
	}
	return &tiktook.CartListResponse{
		List: list,
	}, nil
}
